import Decorator from '../core/Decorator';
import { FAILURE, SUCCESS } from '../constants';
import Tick from '../core/Tick';
import BaseNode from '../core/BaseNode';

// 反转
export default class Inverter extends Decorator {

  constructor(child: BaseNode) {
    super('Inverter', child);
  }

  onTick(tick: Tick, ...args: any[]) {
    var status = this.child.execute(tick, ...args);
    if (status == SUCCESS) {
      status = FAILURE;
    } else if (status == FAILURE) {
      status = SUCCESS;
    }
    return status;
  }
};
